< previous page page_32 next page >

Page 32
0032-01.jpg
Figure 1.16
Example program Auto demonstrates the AutoRedraw
and Paint event handler drawing strategies.
When a form is enlarged, it receives both a Resize event and a Paint event. You already need to redraw the form for the Paint event. It would be nice to avoid drawing the form twice, so you might skip the drawing in the Resize event. You could recalculate drawing parameters during the Resize event and then wait until the Paint event to perform the actual drawing.
Unfortunately, when a form shrinks, it receives only a Resize event. Because no new part of the image has been exposed, the form does not receive a Paint event. If your program waits for a corresponding Paint event, it may never redraw the form. Table 1.3 shows occurrences that cause Resize or Paint events. It is not too difficult to write a program that handles all of these situations correctly.
First, you need to redraw the form any time it receives a Paint event. Doing so handles redrawing the form for every occurrence in this list except when the form is shrunk in size or minimized.
Table 1.3 Occurrences That Cause Resize or Paint Events
WHEN THE FORM IS:THESE EVENTS ARE GENERATED:
CreatedResize, Paint
ExposedPaint
ShrunkResize
EnlargedResize, Paint
MinimizedResize
RestoredResize, Paint

 
< previous page page_32 next page >